const db = require('../db/db')
const fs = require('fs')
const path = require('path')
module.exports = {
    // 通用上传图片
    UPLOADIMG: async (ctx, next) => {
        // 图片地址拼接
        const headPath = 'http://localhost:3000/uploadImgs/'+ctx.req.file.filename
        ctx.body = {
            code: 200,
            fileUrl: headPath,
            filename:ctx.req.file.filename
        }
    },
    // 通用图片删除
    DELUPLOADIMG: async (ctx, next) => {
        const {filename} = ctx.request.body
        // 删除图片
        fs.unlink(path.join(__dirname ,`../public/uploadImgs/${filename}`),  (err)=>{})
        ctx.body = {
            code:200,
            msg:'删除成功'
        }
    }
} 